CONTENTS | INDEX | PREV | NEXT
getchar
NAME
getchar - get character from stdin (MACRO)
SYNOPSIS
#include <stdio.h>
int c = getchar();
FUNCTION
getchar() returns the next available character on stdin or EOF if
no more characters are available. getchar() is equivalent to
getc(stdin).
NOTE
refer to the file_pointer manual page for general information
EXAMPLE
/*
* copy stdin to stdout using getchar/putchar. Normally one uses
* fread/fwrite, but I'll save that for the fread manual page.
*
* note that I output the initial message to stderr so it does
* not get stuck into stdout in case the user has redirected
* stdout.
*
* See getc manual page for equivalent example using getc/putc
*/
#include <stdio.h>
main()
{
int c;
fputs("Type a couple of lines, then ^ (EOF)n", stderr);
while ((c = getchar()) != EOF) {
putchar(c);
}
return(0);
}
INPUTS
none
RESULTS
int c; character 0 to 255, or EOF (-1) returned from stdin
SEE ALSO
putc, putchar, fputc, fread, fwrite, getc